package org.sport.presenter;


import net.sf.json.JSONObject;
import org.sport.logic.Logic_AboutMe;
import org.sport.model.jsonModel.Json_5_detail;
import org.sport.model.jsonModel.Json_5_sign;
import org.sport.model.jsonModel.Json_5_updateDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by zehong
 *
 * 主要用于对接我的页面，展示我的一般信息，以及签到等功能。
 *
 */

@Controller
public class Interface_AboutMe {

    @Autowired
    Logic_AboutMe logicForMe;


    /**
     * 功能：获取详细信息
     * json参数：用户手机号码
     * 返回：用户各种信息
     */
    @RequestMapping(value = "/5/detail", method = RequestMethod.POST)
    public void detail(@RequestBody Json_5_detail json_5_detail
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("进入Interface-5_detail");
        json_5_detail = logicForMe.detail(json_5_detail);
        try {
            response.getWriter().print(JSONObject.fromObject(json_5_detail).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }





    /**
     * 功能：更新用户详细信息
     * json参数：用户手机号码及各种信息
     * 返回：更新结果
     */
    @RequestMapping(value = "/5/updateDetail", method = RequestMethod.POST)
    public void updateDetail(@RequestBody Json_5_updateDetail json_5_updateDetail
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("进入Interface-5_updateDetail");
        json_5_updateDetail = logicForMe.updateDetail(json_5_updateDetail);
        try {
            response.getWriter().print(JSONObject.fromObject(json_5_updateDetail).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }










    /**
     * 功能：签到
     * json参数：用户手机号码
     * 返回：签到结果
     */
    @RequestMapping(value = "/5/sign", method = RequestMethod.POST)
    public void sign(@RequestBody Json_5_sign json_5_sign
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        json_5_sign = logicForMe.sign(json_5_sign);
        try {
            response.getWriter().print(JSONObject.fromObject(json_5_sign).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
